package com.example.card.transactionimplementation;

import cn.hutool.core.util.NumberUtil;
import com.example.card.implemention.ExpireDate;
import com.example.card.abstracttransactions.AddCardTransaction;
import com.example.card.domain.card.CardClassification;
import com.example.card.domain.card.ExpireDataLimit;
import com.example.card.implemention.OilValue;
import com.example.card.implemention.RedCardClassification;

import java.math.RoundingMode;
import java.time.LocalDate;

import static com.example.card.CardConstant.*;

public class AddRedCardTransaction extends AddCardTransaction {

    int oilLabel;
    float price;



    public AddRedCardTransaction(int id, int balance, int oilLabel, float price) {
        super(id, balance);
        this.oilLabel = oilLabel;
        this.price = price;
    }

    @Override
    public int getCardFunction() {
        return ENABLE_CHARGE | ENABLE_OIL_CODE | ENABLE_STORE_CODE | ENABLE_DEDUCT_COIN | ENABLE_DEDUCT_V_OIL;
    }

    @Override
    public int getCardOilLabel() {
        return oilLabel;
    }

    @Override
    public String getCardName() {
        return "红卡";
    }

    @Override
    public String getCardNoPrefix() {
        return "6001";
    }

    @Override
    public Integer getType() {
        return CARD_RED;
    }

    @Override
    public CardClassification getCardClassification() {
        OilValue oilValue = new OilValue(balance, NumberUtil.round(balance/price/100d,2, RoundingMode.DOWN).floatValue());
        return new RedCardClassification(oilValue);
    }

    @Override
    public ExpireDataLimit getExpireDataLimit() {
        LocalDate now = LocalDate.now();
        return new ExpireDate(now, now.plusYears(1));
    }


}
